/**
 *                            License
 * THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS  
 * CREATIVE COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). 
 * THE WORK IS PROTECTED BY COPYRIGHT AND/OR OTHER APPLICABLE LAW.  
 * ANY USE OF THE WORK OTHER THAN AS AUTHORIZED UNDER THIS LICENSE OR  
 * COPYRIGHT LAW IS PROHIBITED.
 * 
 * BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND  
 * AGREE TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE  
 * MAY BE CONSIDERED TO BE A CONTRACT,
 * THE LICENSOR GRANTS YOU THE RIGHTS CONTAINED 
 * HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND CONDITIONS.
 * 
 */
package com.lineage.server.model.item.etcitem.action;

import com.lineage.configure.Config;
import com.lineage.server.PacketCreate;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.item.ItemExecutor;
import com.lineage.server.packetserver.S_ServerMessage;
import com.lineage.server.utils.Random;

/**
 * Class <code>SeikoBlueGreenRuby</code> 精工的蓝、绿、红宝石 - (40931 - 40942).
 * 
 * @author jrwz
 * @version 2012-6-19上午11:47:45
 * @see com.lineage.server.model.item.etcitem.action
 * @since JDK1.7
 */
public final class SeikoBlueGreenRuby extends ItemExecutor {

    /**
     * 取得实例.
     * 
     * @return 实例
     */
    public static ItemExecutor get() {
        return new SeikoBlueGreenRuby();
    }

    /** 精工的蓝、绿、红宝石 - (40931 - 40942). */
    private SeikoBlueGreenRuby() {
    }

    @Override
    public void execute(final L1PcInstance pc, final L1ItemInstance useItem,
            final int readC1, final int readC2, final int targetId,
            final int targetX, final int targetY) {
        final int itemId = useItem.getItemId();
        final int itemobj = targetId;
        final L1ItemInstance l1iteminstance1 = pc.getInventory().getItem(
                itemobj);
        final int earing3Id = l1iteminstance1.getItem().getItemId();
        // 神秘的耳环类
        if ((earing3Id >= 41161) && (41172 >= earing3Id)) {
            if (earing3Id == (itemId + 230)) {
                if ((Random.nextInt(99) + 1) < Config.CREATE_CHANCE_PROCESSING) {
                    final int[] earingId = { 41161, 41162, 41163, 41164, 41165,
                            41166, 41167, 41168, 41169, 41170, 41171, 41172 };
                    final int[] earinglevel = { 21014, 21006, 21007, 21015,
                            21009, 21008, 21016, 21012, 21010, 21017, 21013,
                            21011 };
                    for (int i = 0; i < earingId.length; i++) {
                        if (earing3Id == earingId[i]) {
                            pc.createNewItem(pc, earinglevel[i], 1);
                            break;
                        }
                    }
                } else {
                    pc.sendPackets(new S_ServerMessage(158, l1iteminstance1
                            .getName())); // \f1%0%s 消失。
                }
                pc.getInventory().removeItem(l1iteminstance1, 1);
                pc.getInventory().removeItem(useItem, 1);
            } else {
                PacketCreate.get().sendSinglePackets(pc, "没有任何事情发生");
            }
        } else {
            PacketCreate.get().sendSinglePackets(pc, "没有任何事情发生");
        }
    }
}
